/*****************************************************************************
 * Product: 数据同步解决方案                                                    
 * Copyright (C) 2010-2011  瑞科软件. All Rights Reserved.                                                                       *
 * 改程序是开源的，您可以修改源代码，做二次开发，定制您自己的同步程序                     
 * 您可以通过我们的网站了解详细信息，包括安装与使用指南，  http://www.ruike.org         
 * 																		      			
 *****************************************************************************/
package com.db.sql.err;

public class ForeignErrorStragety implements ErrorStragety {

	private String tableName;
	private String fieldName;
	private String value;

	/**
	 * org.postgresql.util.PSQLException: ERROR: insert or update on table
	 * "c_acctschema" violates foreign key constraint "cperiod_cacctschema"
	 * 详细：Key (c_period_id)=(1000031) is not present in table "c_period".
	 * 
	 * @param error
	 *            Aug 8, 2009
	 */
	public void doError(String error) {
		int index = error.indexOf("is not present in table");
		int prefixIndex = error.indexOf("详细：Key (");
		String prefix = error.substring(prefixIndex + 8, index - 1);
		tableName = error.substring(index + 24);
		tableName = tableName.replaceAll("\"", "");
		tableName = tableName.replace(".", "");
		fieldName = prefix.substring(0, prefix.indexOf(")=("));
		value = prefix.substring(prefix.indexOf(")=(") + 3, prefix
				.lastIndexOf(")"));
	}

	public static void main(String args[]) {
		ForeignErrorStragety aForeignErrorStragety = new ForeignErrorStragety();
		String s = "org.postgresql.util.PSQLException: ERROR: insert or update on table \"c_acctschema\" violates foreign key constraint \"cperiod_cacctschema\"  详细：Key (c_period_id)=(1000031) is not present in table \"c_period\"";
		aForeignErrorStragety.doError(s);
	}

	public String getTableName() {
		return tableName;
	}

	public void setTableName(String tableName) {
		this.tableName = tableName;
	}

	public String getFieldName() {
		return fieldName;
	}

	public void setFieldName(String fieldName) {
		this.fieldName = fieldName;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

}
